<?php
global $_GPC, $_W;
$GLOBALS['frames'] = $this->getMainMenu();
$operation = !empty($_GPC['op']) ? $_GPC['op'] : 'display';
$type=empty($_GPC['type']) ? 'all' :$_GPC['type'];
$state=$_GPC['state'];
$pageindex = max(1, intval($_GPC['page']));
$pagesize=10;
$where=' WHERE a.uniacid=:uniacid and a.state=2';
$data[':uniacid']=$_W['uniacid'];

if(isset($_GPC['keywords'])){
    $where.="  and (a.students_name LIKE  concat('%', :name,'%') or a.parents_name LIKE  concat('%', :name,'%'))";
    $data[':name']=$_GPC['keywords']; 
    $type='all';  
}

 if($type!='all'){
    $where.=" and a.state=".$state;
}

	$pagesize=10;
	$sql="SELECT a.*,b.class_name,d.course_name,e.cate_name FROM ".tablename('snx_users'). " a"  . " left join " . tablename("snx_class") . " b on a.class_id=b.id " . " left join " . tablename("snx_course") . " c on b.cou_id=c.id " . " left join " . tablename("snx_coursecate") . " d on c.c_id=d.id " . " left join " . tablename("snx_school") . " e on d.school_id=e.id ".$where." ORDER BY a.create_time desc";
	$select_sql =$sql." LIMIT " .($pageindex-1) * $pagesize.",".$pagesize;
	$list = pdo_fetchall($select_sql,$data);
	$total=pdo_fetchcolumn("SELECT count(*) FROM ".tablename('snx_users'). " a"  . " left join " . tablename("snx_class") . " b on a.class_id=b.id " . " left join " . tablename("snx_course") . " c on b.cou_id=c.id " . " left join " . tablename("snx_coursecate") . " d on c.c_id=b.id " . " left join " . tablename("snx_school") . " e on d.school_id=e.id ".$where." ORDER BY a.create_time desc",$data);
  // var_dump($list);die;
	$pager = pagination($total, $pageindex, $pagesize);

if($_GPC['op']=='delete'){
    $res=pdo_delete('snx_users',array('id'=>$_GPC['id']));
    if($res){
        message('删除成功！', $this->createWebUrl('user'), 'success');
    }else{
        message('删除失败！','','error');
    }
}
if($_GPC['op']=='tg'){
	$res=pdo_update('snx_users',array('state'=>2),array('id'=>$_GPC['id']));
	if($res){
     message('通过成功！', $this->createWebUrl('user'), 'success');
    }else{
          message('通过失败！','','error');
    }
}
if($_GPC['op']=='jj'){
	$res=pdo_update('snx_users',array('state'=>3),array('id'=>$_GPC['id']));
	if($res){
     message('拒绝成功！', $this->createWebUrl('user'), 'success');
    }else{
          message('拒绝失败！','','error');
    }
}
if(checksubmit('submit2')){
      global $_W,$_GPC;  
      $res=pdo_update('snx_users',array('score'=>$_GPC['score']),array('id'=>$_GPC['id']));
      // if($res){
      //    $data2['score']=$_GPC['score'];
         if($res){
          message('修改成功！', $this->createWebUrl('students'), 'success');
         }else{
          message('修改失败！','','error');
         }
      // }
}
// if($_GPC['op']=='change'){
// 	    $res = pdo_update('snx_users',array('state'=>$_GPC['state']),array('id'=>$_GPC['id']));
// 		if($res){
// 		 message('编辑成功！', $this->createWebUrl('user'), 'success');
// 		}else{
// 			  message('编辑失败！','','error');
// 		}
// 	}
include $this->template('web/students');